package com.imti.mall.sale.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imti.mall.model.sms.pojo.SmsFlashPromotionProductRelation;
import com.imti.mall.model.sms.vo.SmsCouponProductRelationTo;
import com.imti.mall.model.sms.vo.SmsFlashPromotionProductRelationVo;
import com.imti.mall.sale.mapper.SmsFlashPromotionProductRelationDynaSqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.concurrent.BlockingDeque;

@Mapper
public interface SmsFlashPromotionProductRelationDao extends BaseMapper<SmsFlashPromotionProductRelation> {

    /**
     * 根据id修改限时购与商品关系表
     * @param smsFlashPromotionProductRelation
     * @return
     */
    @UpdateProvider(type = SmsFlashPromotionProductRelationDynaSqlProvider.class, method = "updateSmsFlashPromotionProductRelation")
    public Integer updateSmsFlashPromotionProductRelation(SmsFlashPromotionProductRelation smsFlashPromotionProductRelation);

    /**
     * 限时购与商品关系表与限时购场次表 关联查询
     * @param smsFlashPromotionProductRelationVo
     * @return
     */
    @Select(" SELECT sfp.id,sfp.product_id,sfp.flash_promotion_id,sfp.flash_promotion_session_id ,sfp.flash_promotion_count,sps.name,sps.start_time,sps.end_time,COUNT(sfp.product_id) AS product_count\n" +
            " FROM sms_flash_promotion_product_relation sfp,sms_flash_promotion_session  sps\n" +
            " WHERE sfp.flash_promotion_session_id=sps.id  AND sfp.flash_promotion_id=#{flashPromotionId} \n" +
            " GROUP BY sfp.flash_promotion_session_id")
    public List<SmsFlashPromotionProductRelationVo> findSmsFlashPromotionProductRelationVo(SmsFlashPromotionProductRelationVo smsFlashPromotionProductRelationVo);

    /**
     * 查询限时购与商品关系表
     * @param smsCouponProductRelationTo
     * @return
     */
    @SelectProvider(type = SmsFlashPromotionProductRelationDynaSqlProvider.class, method = "findSmsFlashPromotionProductRelation")
    public List<SmsCouponProductRelationTo> findSmsFlashPromotionProductRelation(SmsCouponProductRelationTo smsCouponProductRelationTo);

    @Update("UPDATE pms_product SET promotion_type=5 WHERE id=#{id}")
    public boolean updateProduct(Integer id);

}
